#include "fxcc/core/graph/common/MaterialView.h"
#include "fxcc/core/graph/common/ModelLoader.h"
#include "fxcc/core/graph/common/ShaderLoader.h"
#include "fxcc/core/graph/common/EffectsLoader.h"

void fxcc::graph::common::MaterialView::LoadNativeData()
{
	m_NativeDataMap.OnLoad();
}

void fxcc::graph::common::MaterialView::LoadTextures()
{
	m_Textures.OnLoad();
}

void fxcc::graph::common::MaterialView::OnShaderChanged()
{
	ShaderLoader shaderLoader;
	shaderLoader.Influence(*this, m_EffectToken.m_Key);
	LoadTextures();
}

void fxcc::graph::common::MaterialView::OnLoad()
{
	if (m_EffectToken.m_Key.empty())
	{
		m_EffectToken = ShaderLoader::m_DefaultToken;
	}

	LoadNativeData();
	LoadTextures();

	//OnShaderChanged();

}

void fxcc::graph::common::MaterialView::LoadPropertiesFromSource()
{
	EffectsLoader loader;
	auto effectDesc = loader.GetEffectDesc(m_EffectToken.m_Key);

	if (effectDesc)
	{
		ztclog::info("load data form MaterialData use rule %s", m_EffectToken.m_Key.c_str());
	}

}

bool fxcc::graph::common::MaterialNativeDataMap::OnLoad()
{
	ModelLoader loader;
	m_Value = loader.LoadMaterialNativeData(m_Index.m_TargetFilePath);
	return m_Value.get();
}
